#include<stdio.h>
#include<stdlib.h>
#define max 10
#define dc 100
typedef struct bian{
	char s;
	char e;
	int w;
}Edge;
typedef struct Tu
{
	int vnum,anum;
	char vs[max];
	int as[max][max];
}tu;
int visited[max];
int geti(tu * pg,char c)
{
	int i;
	for(i=0;i<pg->vnum ;i++){
		if(pg->vs [i]==c)
			return i;
	}
}
void cre(tu * pg)
{
	scanf("%d%d",&pg->vnum ,&pg->anum );
	int i,j;
	for(i=0;i<pg->vnum ;i++){
		scanf(" %c",&pg->vs [i]);
	}
	for(i=0;i<pg->vnum ;i++)
		for(j=0;j<pg->vnum ;j++)
			pg->as [i][j]=0;

	char va,vb;
	int k,w;
	for(k=0;k<pg->anum ;k++){
		scanf(" %c %c %d",&va,&vb,&w);
		i=va-'A';
		j=vb-'A';
		pg->as [i][j]=w;
		pg->as [j][i]=w;
	}
}
void printf(tu * pg)
{
	int i,j;
	for(i=0;i<pg->vnum ;i++){
		for(j=0;j<pg->vnum ;j++)
			printf("%5d",pg->as [i][j]);
		printf("\n");
	}
}
void Sf(tu * pg,int i)
{
	visited[i]=1;
	printf("%c ",pg->vs [i]);
	int w;
	for(w=0;w<pg->vnum ;w++){
		if(pg->as [i][w]!=0&&visited[w]==0)
			Sf(pg,w);
	}
}
void sf(tu * pg,char c)
{
	int i;
	for(i=0;i<pg->vnum ;i++)
		visited[i]=0;
	i=geti(pg,c);
	Sf(pg,i);
	printf("\n");
}

int front=0,rear=0;
int dui[dc];
void Bf(tu * pg,int i)
{
	visited[i]=1;
	printf("%c ",pg->vs[i]);
	dui[rear]=i;
	rear++;
	while(front!=rear){
		i=dui[front];
		front++;

		int j;
		for(j=0;j<pg->vnum ;j++){
			if(pg->as [i][j]!=0&&visited[j]==0){
				visited[j]=1;
				printf("%c ",pg->vs [j]);
				dui[rear]=j;
				rear++;
			}
		}
	}
}
void bf(tu * pg,char c)
{
	int i;
	for(i=0;i<pg->vnum ;i++)
		visited[i]=0;
	for(i=0;i<dc;i++)
		dui[i]=0;
	i=geti(pg,c);
	Bf(pg,i);
	printf("\n");
}
int ctr_edge(tu * pg,Edge edges[])
{
	int edgenum=0,i,j;
	for(i=0;i<pg->vnum ;i++)
		for(j=0;j<pg->anum ;j++){
			if(pg->as [i][j]!=0&&pg->as [i][j]<999){
				edges[edgenum].s =pg->vs[i];
				edges[edgenum].e =pg->vs [j];
				edges[edgenum].w =pg->as [i][j];
				edgenum++;
			}
		}
	return edgenum;
}
typedef struct
{
	int w;
	int i;
}lowcost;
void prim(tu * pg,int i)
{
	lowcost cost[max];
	int flag[max];
	int k;
	for(k=0;k<pg->vnum ;k++)
		flag[k]=0;
	for(k=0;k<pg->vnum ;k++)
		cost[i].i =-1;
	flag[i]=1;
	for(k=0;k<pg->vnum ;k++){
		cost[k].w =pg->as [i][k];
		if(cost[k].w ==999)
			cost[i].i =-1;
		else
			cost[i].i =i;
	}
	int n=0;
	while(++n<pg->vnum ){
		int min=999,minpos;
		for(k=0;k<pg->vnum ;k++){
			if(flag[k]==0&&cost[k].w <min){
				min=cost[k].w ;
				minpos=k;
			}
		}
		flag[minpos]=1;
		for(k=0;k<pg->vnum ;k++)
			if(flag[k]=0&&pg->as [minpos][k]<cost[k].w ){
				cost[k].w =pg->as [minpos][k];
				cost[k].i =minpos;
			}
	}
}
int main()
{
	tu g;
	tu * p;
	p=&g;
	char x;
	while(1){
		scanf("%c",&x);
		switch(x){
		case'b'://bf
			break;
		case'c'://cre
			break;
		case'd'://sf
			break;
		case'o'://print
			break;
		case'p'://prim
			break;
		case'q'://end
			break;
		case'j'://dj
			break;
		default:
			break;
		}//switch
	}//while
}